package com.stox.client.ui.javafx.chartingy.widget;

import javafx.scene.control.CheckBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;

import com.stox.client.ui.javafx.chartingy.model.chart.Chart;
import com.stox.client.ui.javafx.chartingy.view.ChartingView;
import com.stox.client.ui.javafx.core.util.CSS;
import com.stox.client.ui.javafx.core.util.UI;
import com.stox.shared.core.i18n.MessageSource;

public class ChartingConfigurationPane extends Pane {

	private final ChartingView chartingView;
	private final CheckBox gridCheckBox = new CheckBox(MessageSource.get("Grid"));
	private final CheckBox crosshairCheckBox = new CheckBox(MessageSource.get("Crosshair"));
	private final CheckBox mainToolBarCheckBox = new CheckBox(MessageSource.get("Main.ToolBar"));
	private final CheckBox drawingToolBarCheckBox = new CheckBox(MessageSource.get("Drawing.ToolBar"));

	public ChartingConfigurationPane(final ChartingView chartingView) {
		this.chartingView = chartingView;
		UI.style(this, CSS.chartingConfigurationPane);
		getChildren().add(new VBox(gridCheckBox, crosshairCheckBox, mainToolBarCheckBox, drawingToolBarCheckBox));
	}

	public void prepare() {
		gridCheckBox.setSelected(chartingView.getPrimaryChart().getGrid().isVisible());
		crosshairCheckBox.setSelected(chartingView.getCrosshair().isVisible());
		mainToolBarCheckBox.setSelected(chartingView.getChartingToolBar().isVisible());
		drawingToolBarCheckBox.setSelected(chartingView.getDrawingToolBar().isVisible());
	}

	public void apply() {
		final Boolean newValue = gridCheckBox.isSelected();
		chartingView.getPrimaryChart().getGrid().setVisible(newValue);
		for (final Chart<?, ?> chart : chartingView.getCharts()) {
			chart.getGrid().setVisible(newValue);
		}

		chartingView.getCrosshair().setVisible(crosshairCheckBox.isSelected());
		chartingView.getChartingToolBar().setVisible(mainToolBarCheckBox.isSelected());
		chartingView.getDrawingToolBar().setVisible(drawingToolBarCheckBox.isSelected());
	}

	public CheckBox getCrosshairCheckBox() {
		return crosshairCheckBox;
	}

}
